let storage = window.localStorage;

class PlayerStorage {
    static getInstance() {
        if (!PlayerStorage.instance) {
            PlayerStorage.instance = new PlayerStorage();
        }
        return PlayerStorage.instance;
    }

    constructor() {
        this._data = storage.getItem('PlayerStorage');

        if (this._data) {
            this._data = JSON.parse(this._data);

        }
        let msg = storage.getItem('msg');
        if (msg) {
            window._msg = JSON.parse(msg);
        } else {
            window._msg = []
        }
    }

    get = () => {
        return this._data;
    }

    getMsg = () => {
        return window._msg;
    }

    set = (data) => {
        this._data = data;
    }

    // getKey = (key) => {
    //     return this._data.key;
    // }

    // set = (key, value) => {
    //     this._data[key] = value;
    //     storage.setItem('userData', JSON.stringify(this._data));
    // }

    save = (data) => {
        console.log(data)
        storage.setItem('PlayerStorage', JSON.stringify(data || this._data));
    }

    saveMsg(msg) {
        storage.setItem('msg', JSON.stringify(msg || window._msg));
    }

    clear = () => {
        this._data = null;
        storage.removeItem('PlayerStorage');
        storage.removeItem('msg');
    }
}


let playerStorage = PlayerStorage.getInstance();
export default playerStorage;